package com.koo.modules.purchase.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koo.common.utils.MyStrUtil;
import com.koo.common.utils.PageUtils;
import com.koo.common.utils.Query;
import com.koo.modules.purchase.dao.PurchasesInboundOrderDetailDao;
import com.koo.modules.purchase.entity.PurchasesInboundOrderDetailEntity;
import com.koo.modules.purchase.service.PurchasesInboundOrderDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class PurchasesInboundOrderDetailServiceImpl extends ServiceImpl<PurchasesInboundOrderDetailDao, PurchasesInboundOrderDetailEntity> implements PurchasesInboundOrderDetailService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Object key = params.get("key");
        LambdaQueryWrapper<PurchasesInboundOrderDetailEntity> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.like(MyStrUtil.isNotEmpty(key), PurchasesInboundOrderDetailEntity::getName, key)
//                  .or().eq(MyStrUtil.isNotEmpty(key), PurchasesInboundOrderDetailEntity::getCode, key);

        IPage<PurchasesInboundOrderDetailEntity> page = this.page(
                new Query<PurchasesInboundOrderDetailEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<PurchasesInboundOrderDetailEntity> listByStoreId(Long storeId) {
        LambdaQueryWrapper<PurchasesInboundOrderDetailEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MyStrUtil.isNotEmpty(storeId), PurchasesInboundOrderDetailEntity::getStoreId, storeId);
        return this.list(wrapper);
    }

    @Override
    public List<PurchasesInboundOrderDetailEntity> listByInBoundId(String inBoundId) {
        LambdaQueryWrapper<PurchasesInboundOrderDetailEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MyStrUtil.isNotEmpty(inBoundId), PurchasesInboundOrderDetailEntity::getInboundId, inBoundId);
        return this.list(wrapper);
    }
}